using UnityEngine;
using System.Collections;

public class BlowerCat : Cat 
{
    public Transform furBallSpawner;
    public Transform furBallPrefab;
    private float jumpTimer;

    private float timeToShoot1, timeToShoot2, timeToShoot3;
    private bool shoot1, shoot2, shoot3;
	
	public Texture2D[] runningAnimation;
	public Texture2D[] jumpingAnimation;
	public Texture2D[] fallingAnimation;

    public override void Start()
    {
        base.Start();
		
		SetAnimations(runningAnimation, jumpingAnimation, fallingAnimation, null, null);
    }

    public override void Update()
    {
        base.Update();

        if(base.attackMode == false)
        {
            RunAnimation("First", "Loop");
        }
		
		if(base.attackMode)
		{
			RunAnimation("Second", "Loop");
		}


        if(jumped)
        {
            jumpTimer += Time.deltaTime;
            Blow();
        }
    }

    private void Blow()
    {
		CheckDificult();
		
        if(jumpTimer >= timeToShoot1 && jumpTimer < timeToShoot2 && shoot1 == false)
        {
            Instantiate(furBallPrefab, furBallSpawner.position, Quaternion.identity);
            shoot1 = true;
            AudioPlayer.Play(AudioPlayer.CAT_BLOW);
        }

        if(jumpTimer >= timeToShoot2 && jumpTimer < timeToShoot3 && shoot2 == false)
        {
            Instantiate(furBallPrefab, furBallSpawner.position, Quaternion.identity);
            shoot2 = true;
            AudioPlayer.Play(AudioPlayer.CAT_BLOW);
        }

        if(jumpTimer >= timeToShoot3 && shoot3 == false)
        {
            Instantiate(furBallPrefab, furBallSpawner.position, Quaternion.identity);
            shoot3 = true;
            AudioPlayer.Play(AudioPlayer.CAT_BLOW);
        }
    }

    public override void Jump()
    {
            meGo.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
            meGo.rigidbody.AddForce(new Vector3(0, yJumpForce, 0));

            timeToShoot1 = Random.Range(0, 0.5f);
            timeToShoot2 = Random.Range(0.6f, 1f);
            timeToShoot3 = Random.Range(1.1f, 1.5f);

            jumped = true;

            AudioPlayer.Play(AudioPlayer.CAT_JUMP);
    }
	
	public void CheckDificult()
	{
		Dificult dificult = CatManager.CheckDificult();
		
		switch (dificult) 
		{
			case Dificult.Level1:
				shoot3 = true;
				shoot1 = true;
				break;
			default:
				break;
		}
	}
}